package com.xuedian.xuanxuan.core.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtils {


	/**
	 * 获取时间戳
	 * @return
     */
	public static String getTimestamp(){
		long time = System.currentTimeMillis();
		String stamp = ""+time;
		return stamp;
	}

	/**
	 * 根据格式转换为时间戳
	 * @param format 时间格式 如yyyy-MM-dd HH:mm:ss
	 * @param time 时间
	 * @return
	 */
	public static String tranFormatTime(String time,String format){
		String re_time = "";
		try {
			SimpleDateFormat   formatter   =   new   SimpleDateFormat   (""+format);
			Date date = formatter.parse(time);
			long l = date.getTime();
			re_time = String.valueOf(l);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return re_time;
	}


	/**
	 * 根据格式获取当前时间
	 * @param format 时间格式 如yyyy-MM-dd HH:mm:ss
	 * @return
	 */
	public static String getCurrentTime(String format){
		SimpleDateFormat   formatter   =   new   SimpleDateFormat   (""+format);
		Date   curDate   =   new   Date(System.currentTimeMillis());//获取当前时间     
		String   str   =   formatter.format(curDate);
		return str;
	}

	/**
	 * 转换日期
	 * @param date
	 * @param format
     * @return
     */
	public static String tranDate(Date date,String format){
		SimpleDateFormat   formatter   =   new   SimpleDateFormat   (""+format);
		Date   curDate   =  date;//获取当前时间
		String   str   =   formatter.format(curDate);
		return str;
	}

	public static Date getTime(){
		Date   curDate   =   new   Date();//获取当前时间
		return curDate;
	}




}